package hibari.server.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LogInServlet extends HttpServlet {
    private static final long serialVersionUID = 6431086567896244036L;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String id = req.getParameter("id");
        String password = req.getParameter("password");

        if (id != null && id.equals("logout")) {
            req.getSession().setAttribute("role", null);
        } else if (id != null && password != null && id.equals("admin") && password.equals("hibari0311")) {
            req.getSession().setAttribute("role", "admin");
            req.getSession().setAttribute("log-in-error-message", null);
        } else {
            req.getSession().setAttribute("log-in-error-message", "ID and PW were incorrect");
        }

        resp.sendRedirect("/Admin/index.jsp");
    }
}
